package helper.base.math

import helper.base.math.GetDecayingEpsilonHelper.t1GetEpsilon
import helper.base.math.GetDecayingEpsilonHelper.t2GetEpsilon
import helper.base.math.GetDecayingEpsilonHelper.t3GetEpsilon
import org.junit.Test

internal class GetDecayingEpsilonHelperTest {
    @Test
    fun t1() {
        val decayRate = 0.005
        val minEpsilon = 0.01

        for (episode in 1..1000) {
            val epsilon = t1GetEpsilon(episode, decayRate, minEpsilon)
            println("Episode: $episode, Epsilon: $epsilon")
        }
    }

    @Test
    fun t2() {
        val decayRate = 0.005
        val minEpsilon = 0.01
        val maxEpisodes = 1000

        for (currentEpisode in 1..maxEpisodes) {
            val epsilon = t2GetEpsilon(currentEpisode, maxEpisodes, decayRate, minEpsilon)
            println("Episode: $currentEpisode, Epsilon: $epsilon")
        }
    }

    @Test
    fun t3() {
        val maxEpisodes = 100

        // 模拟策略逐渐接近最优解的情况
        val decreasingGaps = List(maxEpisodes) { i -> 1.0 / (i + 2) }  // gap从0.5逐渐减小

        println("Scenario 1: Gap is decreasing (policy is improving)")
        for (currentEpisode in 1..maxEpisodes) {
            val episodeFraction = currentEpisode.toDouble() / maxEpisodes.toDouble()
            val epsilon = t3GetEpsilon(episodeFraction, decreasingGaps[currentEpisode - 1])
            println("Episode: $currentEpisode, Gap: ${"%.2f".format(decreasingGaps[currentEpisode - 1])}, Epsilon: ${"%.2f".format(epsilon)}")
        }

        println("\nScenario 2: Gap is increasing (policy is degrading)")
        // 模拟策略逐渐偏离最优解的情况
        val increasingGaps = List(maxEpisodes) { i -> 0.01 * (i + 1) }

        for (currentEpisode in 1..maxEpisodes) {
            val episodeFraction = currentEpisode.toDouble() / maxEpisodes.toDouble()
            val epsilon = t3GetEpsilon(episodeFraction, increasingGaps[currentEpisode - 1])
            println("Episode: $currentEpisode, Gap: ${"%.2f".format(increasingGaps[currentEpisode - 1])}, Epsilon: ${"%.2f".format(epsilon)}")
        }

        println("\nScenario 3: Gap is constant (policy is not changing)")
        // 模拟策略不变的情况
        val constantGap = 0.5

        for (currentEpisode in 1..maxEpisodes) {
            val episodeFraction = currentEpisode.toDouble() / maxEpisodes.toDouble()
            val epsilon = t3GetEpsilon(episodeFraction, constantGap)
            println("Episode: $currentEpisode, Gap: ${"%.2f".format(constantGap)}, Epsilon: ${"%.2f".format(epsilon)}")
        }
    }
}